package chapter12.eg1;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslHandler;
import javax.net.ssl.SSLEngine;

public class SecureChatServerInitializer extends ChatServerInitializer {
  private final SslContext ctx;

  public SecureChatServerInitializer(ChannelGroup group, SslContext ctx) {
    super(group);
    this.ctx = ctx;
  }

  @Override
  protected void initChannel(Channel ch) throws Exception {
    super.initChannel(ch);
    SSLEngine engine = ctx.newEngine(ch.alloc());
    engine.setUseClientMode(false);
    ch.pipeline().addFirst(new SslHandler(engine));
  }
}
